package com.cqyc.shop.services;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cqyc.shop.comm.commException;
import com.cqyc.shop.dao.UserDao;
import com.cqyc.shop.domain.User;

public class UserServices {

	UserDao userDao = new UserDao();
	private Logger logger = LoggerFactory.getLogger(getClass());
	public User findcode(String usercode, String password) {
		User user = userDao.findcode(usercode);
		if(user==null || password==null) {
			logger.debug("查找账号或者密码输入失败");
			throw new commException("没有找到数据库中对应的账号或者密码输入为空");
		}else if (!usercode.equals(user.getUsercode()) || !password.equals(user.getPassword())) {
			throw new commException("账号输入错误或者密码输入错误");
		}
		return user;
	}
	/**
	 * 注册用户
	 * @param user
	 */
	public void register(User user) {
			userDao.save(user);
	}

}
